home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 50
/
Volume 50 - JOGO DISK .iso
/
Games
/
moonstonemadness.swf
/
scripts
/
__Packages
/
TakFlying.as
< prev
next >
Wrap
Text File
|
2007-09-27
|
9KB
|
302 lines
class TakFlying extends Library.State
{
static var UP_LEFT_LIMIT = 50;
static var UP_RIGHT_LIMIT = 550;
static var DOWN_LEFT_LIMIT = 50;
static var DOWN_RIGHT_LIMIT = 550;
static var START_SPEED = 60;
static var SPEED_LOOSE = 0.35;
static var GRAVITY_GAIN = 0.85;
static var MAX_DROP_SPEED = 20;
static var MAX_SPEED_AIR = 8;
static var ACCELERATION_AIR = 0.75;
static var DIRECTION_CHANGE_FACTOR_AIR = 0.85;
function TakFlying(__mcRef)
{
super(__mcRef);
this.bGoingLeft = false;
this.bGoingRight = false;
this.oKeysManager = new Library.Utils.KeysManager();
this.oKeysManager.setListenerForKey(this,38);
this.oKeysManager.setListenerForKey(this,40);
this.oKeysManager.setListenerForKey(this,37);
this.oKeysManager.setListenerForKey(this,39);
this.nFollowY = -50;
this.nSpeedX = 0;
this.nSpeedY = - TakFlying.START_SPEED;
this.setState("FlyUp");
MiniGameManager.__get__Instance().doAddListener(this);
}
static function get Instance()
{
return TakFlying.oCtrl;
}
function onKeyManagerEvent(__nEvent, __nCode)
{
if(!this.__get__Paused())
{
switch(__nEvent)
{
case Library.Utils.KeysManager.EVENT_KEY_DOWN:
switch(__nCode)
{
case 37:
this.bGoingLeft = true;
break;
case 39:
this.bGoingRight = true;
break;
case 38:
if(this.bFlyingDown)
{
this.setState("FlyDownSlow");
}
break;
case 40:
if(this.bFlyingDown)
{
this.setState("FlyDownFast");
}
}
break;
case Library.Utils.KeysManager.EVENT_KEY_UP:
switch(__nCode)
{
case 37:
this.bGoingLeft = false;
break;
case 39:
this.bGoingRight = false;
break;
case 38:
if(this.bFlyingDown)
{
if(this.oKeysManager.isKeyDown(40))
{
this.setState("FlyDownFast");
}
else
{
this.setState("FlyDown");
}
}
break;
case 40:
if(this.bFlyingDown)
{
if(this.oKeysManager.isKeyDown(38))
{
this.setState("FlyDownSlow");
}
else
{
this.setState("FlyDown");
}
}
}
}
}
}
function doSoundEvent(__nEvent, __oSound)
{
if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
{
if(__oSound == this.oFlappingSound)
{
delete this.oFlappingSound;
}
}
}
function doPause()
{
super.doPause();
this.oFlappingSound.doPause();
}
function doResume()
{
super.doResume();
this.oFlappingSound.doResume();
}
function doDestroy()
{
this.oKeysManager.doDestroy();
delete this.oKeysManager;
delete TakFlying.oCtrl;
MiniGameManager.__get__Instance().doRemoveListener(this);
this.oFlappingSound.doDestroy();
delete this.oFlappingSound;
}
function get FollowY()
{
return this.nFollowY;
}
function get Ref()
{
return this.mcRef;
}
function doFlyUp()
{
this.doMoveY();
this.nLeftLimit = TakFlying.UP_LEFT_LIMIT;
this.nRightLimit = TakFlying.UP_RIGHT_LIMIT;
this.nSpeedXMaxModifier = -2;
this.doMoveX();
this.bFlyingDown = false;
if(this.nSpeedY >= -2)
{
this.setState("FlyChange");
}
}
function doFlyChange()
{
this.doMoveY();
this.doMoveX();
if(this.isStateComplete())
{
if(this.oKeysManager.isKeyDown(40))
{
this.setState("FlyDownFast");
}
else if(this.oKeysManager.isKeyDown(38))
{
this.setState("FlyDownSlow");
}
else
{
this.setState("FlyDown");
}
}
}
function doFlyDownSlow()
{
this.nSpeedYMaxModifier = -10;
this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier,1.5);
this.doFall();
}
function doFlyDownFast()
{
this.nSpeedYMaxModifier = 50;
this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier,2.5);
this.doFall();
}
function doFlyDown()
{
this.nSpeedYMaxModifier = 0;
this.doFall();
}
function doFall()
{
this.doMoveY();
this.nLeftLimit = TakFlying.DOWN_LEFT_LIMIT;
this.nRightLimit = TakFlying.DOWN_RIGHT_LIMIT;
this.nSpeedXMaxModifier = 0;
this.doMoveX();
this.bFlyingDown = true;
}
function doMoveY()
{
if(this.nSpeedY < 0)
{
this.nSpeedY += TakFlying.SPEED_LOOSE;
}
else
{
this.nSpeedY += TakFlying.GRAVITY_GAIN;
if(this.nFollowY <= -230)
{
this.nFollowY = -230;
}
else
{
this.nFollowY -= 5;
}
}
if(this.nSpeedY > TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier)
{
this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier,0.5);
}
if(this.mcRef._y + this.nSpeedY < 0)
{
this.mcRef._y += this.nSpeedY;
}
else
{
this.setState("FlyDown");
this.doLockState();
this.mcRef._y += this.nSpeedY;
MiniGameManager.__get__Instance().doMinigameEnd();
}
}
function doMoveX()
{
if(this.bGoingRight)
{
if(this.nSpeedX < 0)
{
this.nSpeedX *= TakFlying.DIRECTION_CHANGE_FACTOR_AIR;
}
if(this.nSpeedX < TakFlying.MAX_SPEED_AIR + this.nSpeedXMaxModifier)
{
this.nSpeedX += TakFlying.ACCELERATION_AIR;
}
}
else if(this.bGoingLeft)
{
if(this.nSpeedX > 0)
{
this.nSpeedX *= TakFlying.DIRECTION_CHANGE_FACTOR_AIR;
}
if(this.nSpeedX > - (TakFlying.MAX_SPEED_AIR + this.nSpeedXMaxModifier))
{
this.nSpeedX -= TakFlying.ACCELERATION_AIR;
}
}
else
{
this.nSpeedX = Library.Utils.MoreMath.getReachZero(this.nSpeedX,TakFlying.ACCELERATION_AIR);
}
if(this.mcRef._x + this.nSpeedX > this.nLeftLimit && this.mcRef._x + this.nSpeedX < this.nRightLimit)
{
this.mcRef._x += this.nSpeedX;
}
else
{
this.nSpeedX = 0;
}
}
function doLoadStateAction()
{
super.doLoadStateAction();
switch(this.sState)
{
case "FlyChange":
MiniGameManager.__get__Instance().doStopWinds();
break;
case "FlyDown":
MiniGameManager.__get__Instance().doStartWindNormal();
if(this.oFlappingSound != undefined)
{
this.oFlappingSound.setFadeRate(15);
this.oFlappingSound.doFadeTo(0);
}
break;
case "FlyDownFast":
MiniGameManager.__get__Instance().doStartWindFast();
if(this.oFlappingSound != undefined)
{
this.oFlappingSound.setFadeRate(15);
this.oFlappingSound.doFadeTo(0);
}
break;
case "FlyDownSlow":
MiniGameManager.__get__Instance().doStartWindSlow();
if(this.oFlappingSound == undefined)
{
this.oFlappingSound = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"SkySlow.wav",10,999);
this.oFlappingSound.doAddListener(this);
}
this.oFlappingSound.doFadeTo(60);
}
}
}